package xyz.scootaloo.oj.offer

import org.junit.Test
import xyz.scootaloo.oj.ds.TreeNode
import xyz.scootaloo.oj.ds.helper.CollectionBuilder

/**
 * @author flutterdash@qq.com
 * @since 2021/4/11 11:52
 */
class P27 {

    fun mirrorTree(root: TreeNode?): TreeNode? {
        if (root == null) return null
        if (root.left == null && root.right == null) return root
        val tmpNode: TreeNode? = root.left
        root.left = root.right
        root.right = tmpNode
        mirrorTree(root.left)
        mirrorTree(root.right)
        return root
    }

    @Test
    fun test0() {
        val root = CollectionBuilder.initTree()
            .setRoot(4)
            .addLevel(2, 7)
            .addLevel(1, 3, 6, 9)
            .build()
        val res = mirrorTree(root)
        println(res)
    }

}
